#ifndef Application_H
#define Application_H

#include "GLAllInOne.h"

using namespace glm;
namespace ManchyGL
{
	class Systems;
	class SystemBase;
	class Scene;
	class Camera;

	class Application
	{
	private:
		static void framebuffer_size_callback(GLFWwindow* wnd, int, int);

	private:
		const char* _title;
		int _width;
		int _height;

		int _vpX, _vpY, _vpWidth, _vpHeight;

		int _clearMask;
		vec4 _bgColor;

		int _targetFrameRate;
		float _targetFrameInterval;

		int _frameCount;
		float _time;
		float _lastTime;
		float _deltaTime;

		bool _isRunning;
		bool _destroyed;
	private:
		GLFWwindow *_window;
		Systems* _systems;
		Scene* _scene;
		Camera* _camera;
	public:
		Application();
		~Application();

		void AddSystem(SystemBase* system);
		void SetTargetFrameRate(int value);
		int GetTargetFrameRate();
		int GetFrameCount();
		float GetTime();
		float GetDeltaTime();

		void SetTitle(const char* title);
		void SetSize(int width, int height);
		int GetWidth();
		int GetHeight();
		void SetBgColor(float r, float g, float b, float a);
		void SetBgColor(vec4 color);
		vec4 GetBgColor();
		void SetClearMask(int mask);
		GLFWwindow* GetWindow();
		Scene* GetScene();
		Camera* GetCamera();

	public:
		virtual int Run();

	protected:
		virtual int Init();
		virtual bool CheckGameLoop();
		virtual void OnPreFrame();
		virtual void OnFrame();
		virtual void OnRender();
		virtual void OnPostFrame();
	};
}
#endif